package C035;

import java.util.HashMap;
import java.util.Scanner;

/**
 * ClassName: C01
 * Package: C035
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/1/7 20:48
 * @Version 1.0
 * @Since 1.0
 */
public class C01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k, v;
        for (int i = 0; i < n; i++) {
            int option = scanner.nextInt();
            if(option == 1) {
                k = scanner.nextInt();
                v = scanner.nextInt();
                put(k, v);
            }
            if(option == 2) {
                k = scanner.nextInt();
                System.out.println(get(k));
            }
            if(option == 3) {
                v = scanner.nextInt();
                setAll(v);
            }
        }
    }

    static HashMap<Integer, Integer[]> map = new HashMap<>();
    static int allValue = -1;
    static int allValueTime = -1;
    static int curTime = 0;

    /**
     * 增 与 改
     * @param k
     * @param v
     */
    public static void put(int k, int v) {
        if(map.containsKey(k)) {
            Integer[] valArr = map.get(k);
            valArr[0] = v;
            valArr[1] = curTime ++;
            map.put(k, valArr);
        }else {
            Integer[] valArr = {v, curTime++};
            map.put(k, valArr);
        }
    }

    /**
     * 查找对应的k对应的v
     * @param k
     */
    public static int get(int k) {
        if(!map.containsKey(k)) {
            return -1;
        }

        Integer[] valArr = map.get(k);
        if(allValueTime > valArr[1]) {
            return allValue;
        }else {
            return valArr[0];
        }
    }

    public static void setAll(int v) {
        allValue = v;
        allValueTime = curTime ++;
    }

}
